<?php require_once(dirname(__FILE__) . '/inc/config.inc.php');
IsModelPriv('goodsorder');
require_once "function.php";
$id = htmlspecialchars($id);


/*
进度：
0 已经撤单
1 报修成功
2 客服已经联系
3 系统已经派单
4 工程师接单
5 维修完成
6 已经评价
*/

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>任务详情</title>
    <link href="templates/style/admin.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="templates/js/jquery.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="ui/css/bootstrap.min.css">
    <link rel="stylesheet" href="ui/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="templates/js/zoomify.min.css">
    <script language="javascript" type="text/javascript" src="DatePicker/WdatePicker.js"></script>


</head>

<body style="width:890px;">
<?php

$sql = "SELECT f.*,t.classname as typename,j.dataname as jinduname,d.title as devicename,f.op_manageid as op_manangid FROM `#@__order` as f
		left join `#@__tasktype`  as t on t.id=f.apply_type  
		left join `#@__task`  as d on d.id=f.apply_device
		left join `#@__cascadedata`  as j on j.datavalue=f.jindu  
		WHERE  j.datagroup='jindu'  AND   f.is_delete='0' and   f.id='$id' ";


$row = $dosql->GetOne($sql);

$odernum = date("Ymd", $row['post_time']) . "-" . $row['id'];

//故障图片
$picurl_arr = explode(',', $row['picfiles']);
$pic_lists = "";
array_pop($picurl_arr);
for ($i = 0; $i < count($picurl_arr); $i++) {
    $pic_lists .= '<li class="example"><img src="' . $picurl_arr[$i] . '" width=120/></li>';
}

//完修图片
$over_picurl_arr = explode(',', $row['over_picurls']);
$over_pic_lists = "";
array_pop($over_picurl_arr);
for ($i = 0; $i < count($over_picurl_arr); $i++) {
    $over_pic_lists .= '<li class="example"><img src="' . $over_picurl_arr[$i] . '" width=120/></li>';
}

$jindu = intval($row['jindu']);


$qiang_str = "";
if ($row['mode'] == 'q') {
    $qiang_str = '<span class="label label-success">抢单</span>';
}
if ($row['mode'] == 'p') {
    $qiang_str = '<span class="label label-danger">派单</span>';
}
if ($row['mode'] == 'z') {
    $qiang_str = '<span class="label label-danger">自处理</span>';
}

?>
<h1 class="tit">任务详情</h1>
<div class="order_top">
    <div class="order_top1">单号：<?php echo $odernum; ?></div>
    <div class="order_top1 t_fr">创建日期：<?php echo date("Y年m月d日", $row['post_time']); ?></div>
</div>
<table width="200" border="1" class="table table-bordered">
    <tr>
        <td width="100">单位：</td>
        <td><?php echo $row['school']; ?></td>
        <td width="100">联系人：</td>
        <td><?php echo $row['truename'] . "    " . $row['mobile']; ?> </td>
    </tr>
    <tr>
        <td>地址：</td>
        <td> <?php echo $row['address'] ?></td>
        <td>位置信息：</td>
        <td id="apply_address_info"><?php if (empty($row['poster'])) {
                echo $row['apply_address'] . "<br/>位置描述：" . $row['apply_address_name'];
            } else {
                echo "商务直接派单，不显示位置信息";
            } ?></td>
    </tr>
    <tr>
        <td>服务类型</td>
        <td><?php echo $row['typename']; ?></td>
        <td>设备类型：</td>
        <td><?php echo $row['devicename'] ?></td>
    </tr>
    <tr class="red">
        <td>执行人：</td>
        <td colspan="3">
            <?php
            if (!empty($row['manageid'])) {
                $m_str = $row['manageid'];
                $m_arr = explode(",", $m_str);
                foreach ($m_arr as $key => $val) {
                    echo ' <i class="glyphicon glyphicon-user"></i>      ' . getManage($val);
                }

            }

            ?>
        </td>
    </tr>

    <tr class="">
        <td>任务时间：</td>
        <td colspan="3">
            <i class="glyphicon glyphicon-off green"></i> <?php echo date("Y-m-d H:i:s", $row['begintime']) . "  <i  class=' red glyphicon glyphicon-random'></i>        " . date("Y-m-d H:i:s", $row['endtime']) ?>
        </td>
    </tr>
    <tr>
        <td>服务类型</td>
        <td><?php echo $qiang_str . "  " . $row['typename']; ?></td>
        <td>设备类型：</td>
        <td><?php echo $row['devicename'] ?>
            <?php
            if (!empty($row['device_num'])) {
                echo "<b class='red'>序列号：" . $row['device_num'] . "</b>";
                $sn_num = $row['device_num'];
                $row_sn = $dosql->GetOne("SELECT * FROM `#@__sn` WHERE `sn`='$sn_num' ");
                if (is_array($row_sn) && isset($row_sn['id'])) {
                    // 过期时间
                    $guoqi = $row_sn['end_time'] + 86400;
                    if (time() > $guoqi) {
                        echo '<span class="label label-danger mr-5">过保</span>';
                    }
                }
            }
            ?>
        </td>
    </tr>

    <tr>
        <td>任务详情：</td>
        <td colspan="3"><?php echo $row['content'] ?></td>
    </tr>
    <tr>
        <td>故障图片：</td>
        <td colspan="3">
            <ul class="photo_list"><?php echo $pic_lists ?></ul>
        </td>
    </tr>
    <tr>
        <td>任务进度：</td>
        <td colspan="3">
            <ul>
                <?php
                $dosql->Execute("SELECT * FROM `#@__order_log` WHERE orderid='$id'  ORDER BY id asc");
                while ($row2 = $dosql->GetArray()) {
                    ?>
                    <li>
                        <i class="glyphicon glyphicon-ok-sign"><?php echo $row2['op'] ?></i> <?php echo date("Y-m-d H:i:s", $row2['op_time']) ?>
                        <span class="red">   <?php echo getManage($row2['manageid']) ?></span></li>
                    <?php
                }
                ?>
            </ul>
        </td>
    </tr>
</table>
<?php
if ($jindu == '1') {
    echo "没有联系客户，不能中止！<br/>请联系客户后，任务状态变更为 【客服已经联系】  ; <br/>再进行中止操作！";
    exit;
}

if ($jindu == '0') {
    echo "任务已经中止了！无需重复操作";
    exit;
}

if ($jindu < 5) {
    ?>
    <div class="lianxi_box">
        中止原因：
        <textarea name="stopremark" id="stopremark" class="form-control w500"></textarea>
        <button type="button" class="btn btn-danger" onclick="stoporder('<?php echo $id; ?>')">确认中止</button>
    </div>
    <?php

} else {
    echo "已经完成的任务，不能中止！";
    exit;
}
?>
<script>
    function stoporder(id) {
        var _stopremark = $("#stopremark").val();
        $.ajax({
            type: 'POST',
            url: "op.php",
            data: {id: id, op: 'stop', stopremark: _stopremark},
            dataType: 'JSON',
            success: function (result) {
                console.log(result);
                if (result.errno == 0) {
                    console.log(result.msg);
                    if (result.msg === "ok") {
                        $(".lianxi_box").hide();
                        layer.msg('操作成功');
                        window.location.reload();

                    } else {
                        layer.msg('操作失败');
                    }
                }
            }
        });

    }


</script>
<script src="templates/js/zoomify.min.js"></script>

<script type="text/javascript">
    $('.example img').zoomify();
</script>
</body>
</html>